@extends('layout.member')

@section('body')
  <div class="panel active">
    <div class="panel-head">
      <h4>
        物料列表
      </h4>
    </div>
    <div class="panel-body">
      <div class="demoTable">
        搜索ID：
        <div class="layui-inline">
          <input class="layui-input" name="id" id="demoReload" autocomplete="off">
        </div>
        搜索ID：
        <div class="layui-inline">
          <input class="layui-input" name="id" id="demoReload" autocomplete="off">
        </div>
        <button class="layui-btn" data-type="reload">搜索</button>
        <a href="{{route('materiel.create')}}">
          <button class="layui-btn fr">添加物料</button>
        </a>
      </div>
      <!-- tab -->
      <table class="table table-bordered layui-table"
             lay-data="{url:'{{route('member.materiel.layui.list')}}', page:true,limit:20,id:'materielReload'}"
             lay-filter="materiel">
        <thead>
        <tr>
          <th lay-data="{field:'id',align: 'center'}">物料编号</th>
          <th lay-data="{field:'materiel_type',align: 'center', sort: true}">物料类型</th>
          <th lay-data="{field:'name',align: 'center', sort: true}">物料名称</th>
          <th lay-data="{field:'overt_phone',align: 'center', sort: true}">外显号码</th>
          <th lay-data="{field:'seat_phone',align: 'center', sort: true}">坐席号码</th>
          <th lay-data="{field:'is_status',align: 'center', sort: true}">物料状态</th>
          <th lay-data="{field:'created_at',align: 'center', sort: true}">添加时间</th>
          <th lay-data="{field:'',width:420,align: 'center',toolbar: '#materiel'}">操作</th>
        </tr>
        </thead>
      </table>
    </div>
  </div>
  <script type="text/html" id="materiel">
    <button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="setUrl">设置网址<span class="layui-badge layui-bg-gray">@{{ d.materiel_url_count }}</span></button>
    <button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="setApp">设置APP<span class="layui-badge layui-bg-gray">@{{ d.materiel_app_count }}</span></button>
    <button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="setPhone">设置号码<span class="layui-badge layui-bg-gray">@{{ d.materiel_phone_count }}</span></button>
    <button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">编辑</button>
  </script>
@endsection
@section('js')
  <script type="text/javascript">
      layui.use(['form', 'table'], function () {
          var table = layui.table;
          //监听工具条
          table.on('tool(materiel)', function (obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
              var data = obj.data; //获得当前行数据
              var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
              if (layEvent === 'setUrl') {
                  //设置网址
                  //设置APP物料
                  layer.open({
                      title: '设置网址物料',
                      type: 2,
                      area: ['100%', '100%'],
                      fixed: false, //不固定
                      maxmin: true,
                      content: '{{url('/member/materielUrl')}}?mp=' + data.id
                  });
              } else if ((layEvent === 'setPhone')) {
                  //设置号码
                  layer.open({
                      title: '设置号码物料',
                      type: 2,
                      area: ['100%', '100%'],
                      fixed: false, //不固定
                      maxmin: true,
                      content: '{{url('/member/materielPhone')}}?mp=' + data.id
                  });
              } else if ((layEvent === 'setApp')) {
                  //设置APP物料
                  layer.open({
                      title: '设置APP物料',
                      type: 2,
                      area: ['100%', '100%'],
                      fixed: false, //不固定
                      maxmin: true,
                      content: '{{url('/member/materielApp')}}?mp=' + data.id
                  });
              } else if ((layEvent === 'edit')) {
                  //编辑
                  window.location.href = '{{url('/member/materiel')}}/' + data.id + '/edit';
              }
          });

          var $ = layui.$, active = {
              reload: function () {
                  var search_city_id = $('#search_city_id').val();
                  var search_position = $('#search_position').val();
                  var search_menu = $('#search_menu').val();
                  var search_title = $('#search_title').val();
                  //执行重载
                  table.reload('bannerReload', {
                      page: {
                          curr: 1 //重新从第 1 页开始
                      }
                      , where: {
                          search_city_id: search_city_id,
                          search_position: search_position,
                          search_menu: search_menu,
                          search_title: search_title
                      }
                  });
              }
          };
          $('.search-content .search').on('click', function () {
              var type = $(this).data('type');
              active[type] ? active[type].call(this) : '';
          });
      });
  </script>
@append